{% extends "index.html" %}
{% block base_content %}
<li><a href="#"></a></li>
{% endblock %}
{% block content %}
<div class="container">
    <form style="margin:100px">
        <div class="input-group">
            <span class="input-group-addon">昵称</span>
            <input type="password" class="form-control" placeholder="Nickname" id="nickname">
        </div><br>
        <div class="input-group">
            <span class="input-group-addon">邮箱</span>
            <input type="text" class="form-control" placeholder="Email" id="email">
        </div><br>
        <div class="input-group">
            <span class="input-group-addon">密码</span>
            <input type="password" class="form-control" placeholder="Password" id="password">
        </div><br>
        <div class="input-group">
            <span class="input-group-addon">确认密码</span>
            <input type="password" class="form-control" placeholder="Password" id="password2">
        </div><br>
        <div style="text-align:center;margin:10px">
            <button type="button" class="btn btn-default" onclick="register()">注册</button><br>
            <a href="/register">去登录</a>
        </div>
    </form>
</div>
{% block styles %}
<link rel="stylesheet" href="/static/css/toastr.min.css">
{{super()}}
{% endblock %}
{% block scripts %}
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/js/toastr.min.js"></script>
<script src=""></script>
{{super()}}
{% endblock %}
<script>
function register(){
    if($('#nickname').val()){
        if($('#email').val()){
            if($('#password').val()){
                if($('#password2').val()){
                    if($('#password').val() == $('#password2').val()){
                        formdata = {
                            'nickname': $('#nickname').val(),
                            'email': $('#email').val(),
                            'password':$('#password').val()
                        }
                        $.ajax({
                            data:JSON.stringify(formdata),
                            url:'/register',
                            type:'POST',
                            dataType:'json',
                            contentType:'application/json'
                        })
                    }else{
                        toastr['error']('两次密码不同')
                    }
                }else{
                    toastr['error']('第二次密码未输入')
                }
            }
        }else{
            toastr['error']("缺少email")
        }
    }else{
        toastr['error']("缺少昵称")
    }
}
</script>
{% endblock %}